{
  LW Types -- LightWave Common Types

  This unit contains type declarations common to all aspects of
  LightWave.

  Based on lwtypes.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit LW_Types;

{$mode objfpc}{$H+}

interface

type
  PUInt32 = ^UInt32;

  PLWImage       = Pointer;
  TLWBufferValue = Single ;
  PLWPixmap      = Pointer;
  PLWTexture     = Pointer;
  PNodeEditor    = Pointer;
  PItemInstance  = Pointer;

  TLWFrame       = Integer;
  PLWTime        = ^TLWTime;
  TLWTime        = Double ;

  TLWFVector2    = array [0..1]       of Single;
  TLWFVector     = array [0..2]       of Single;
  TLWFVector4    = array [0..3]       of Single;

  TLWDVector2    = array [0..1]       of Double;
  TLWDVector     = array [0..2]       of Double;
  TLWDVector4    = array [0..3]       of Double;

  TLWFMatrix3    = array [0..2, 0..2] of Single;
  TLWFMatrix4    = array [0..3, 0..3] of Single;
  TLWDMatrix3    = array [0..2, 0..2] of Double;
  TLWDMatrix4    = array [0..3, 0..3] of Double;

  PLWID          = PUInt32;
  TLWID          = UInt32 ;

  TLWCommandCode = Integer;

  PLWChannel     = Pointer;

  {
    Persistent instances are just some opaque data object referenced
    by void pointer.

    Errors from handler functions are human-readable strings, where a null string
    pointer indicates no error.
  }
  PLWInstance = Pointer;
  PLWError    = PChar;
  PPLWError   = ^PLWError;

  PLWItem     = Pointer;
  PPLWItem    = ^PLWItem;

function LWID_(const A, B, C, D: Char) : TLWID;

{
  These are useful to support 64bit architectures of Mac universal binaries
  where 'long' and pointers are 8bytes (The LP64 programming model)
}
function PTR2INT      (const X : Pointer) : Integer;
function PTR2UINT     (const X : Pointer) : UInt32 ;
function INT2PTR      (const X : Integer) : Pointer;
function UINT2PTR     (const X : UInt32 ) : Pointer;

function LWITEMID2INT (const X : PLWItem) : Integer;
function LWITEMID2UINT(const X : PLWItem) : UInt32 ;
function INT2LWITEMID (const X : Integer) : PLWItem;
function UINT2LWITEMID(const X : UInt32 ) : PLWItem;

implementation

function LWID_(const A, B, C, D : Char) : TLWID; inline;
begin
  Result := (TLWID(A) shl 24) or
            (TLWID(B) shl 16) or
            (TLWID(C) shl  8) or
             TLWID(D)       ;
end;

function PTR2INT      (const X : Pointer) : Integer; inline;
begin
  Result := Integer(SizeUInt(X));
end;
function PTR2UINT     (const X : Pointer) : UInt32 ; inline;
begin
  Result := UInt32(SizeUInt(X));
end;
function INT2PTR      (const X : Integer) : Pointer; inline;
begin
  Result := Pointer(SizeUInt(X));
end;
function UINT2PTR     (const X : UInt32 ) : Pointer; inline;
begin
  Result := Pointer(SizeUInt(X));
end;

function LWITEMID2INT (const X : PLWItem) : Integer; inline;
begin
  Result := PTR2INT(X);
end;
function LWITEMID2UINT(const X : PLWItem) : UInt32 ; inline;
begin
  Result := PTR2UINT(X);
end;
function INT2LWITEMID (const X : Integer) : PLWItem; inline;
begin
  Result := PLWItem(INT2PTR(X));
end;
function UINT2LWITEMID(const X : UInt32 ) : PLWItem; inline;
begin
  Result := PLWItem(UINT2PTR(X));
end;

end.

